package fms.models;
 
import java.util.List;
 
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.Form8;
 
 
public class Form8DAO {
 
    private SqlSessionFactory sqlSessionFactory;
 
    public Form8DAO(){
    	try{
    		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
    	}catch(Exception e) {
    		System.out.println("failed to get sqlSessionFactory");
    	}
    }
 
    /**Returns the list of all Form8 instances from the database*/
    @SuppressWarnings("unchecked")
    public List<Form8> selectAll(){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            List<Form8> list = session.selectList("Form8.getAll");
            return list;
        } finally {
            session.close();
        }
    }
 
    /**Returns a Form8 instance from the database*/
    public Form8 selectById(int entry_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Form8 form8 = (Form8) session.selectOne("Form8.getById", entry_no);
            return form8;
        } finally {
            session.close();
        }
    }
 
    /**Returns a Form8 instance from the database
    public Form9 getAllPending(String status){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Form8 form8 = (Form8) session.selectOne("Form8.getAllPending", status);
            return form8;
        } finally {
            session.close();
        }
    }*/
    
    /**Updates an instance of Form8 in the database*/
    public void update(Form8 form8){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Form8.update", form8);
            session.commit();
        } finally {
            session.close();
        }
    }
    
    /**Updates the status of Form8 in the database
    public void updateStatus(int payroll_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Form8.updateStatus", payroll_no);
            session.commit();
        } finally {
            session.close();
        }
    }*/
 
    /** Insert an instance of Form8 into the database*/
    public void insert(Form8 form8){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.insert("Form8.insert", form8);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Delete an instance of Form8 from the database*/
    public void delete(int entry_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.delete("Form8.deleteById", entry_no);
            session.commit();
        } finally {
            session.close();
        }
    }
}